<template>
  <div class="mb-10">
    <div class="flex-box mb-10">
      <div class="flex-box-left">
        <span>申领单号：</span><span>{{ infoList.recipientApplyId }}</span><span class="color-yellow ml-5 mr-5">计划领用时间:</span><span
          class="color-yellow mr-5"
        >{{ infoList.plantime }}</span>
        <span class="color-red ml-5">{{ infoList.applyType }}</span>
        <span class="color-gray ml-5">{{ infoList.note }}</span>
        <span v-if="infoList.applyTypeId==='6'&&infoList.oldPrjCode!==''" class="color-black ml-5">(原项目编码:{{ infoList.oldPrjCode }})</span>
        <span
          v-if="
            infoList.isPush === '0' && infoList.applyTypeId !== '6'
          "
          class="color-red ml-5"
        >同步仓储失败</span>
        <button
          v-if="
            infoList.isPush === '0' && infoList.applyTypeId !== '6' &&  isEdit && metaEdit
          "
          class="pms-button-primary ml-5"
          @click="handleDoRetryApply(infoList,'01')"
        >
          同步仓储
        </button>
        <span
          v-else-if="
            infoList.isPush === '2' && infoList.applyTypeId !== '6'
          "
          class="color-red"
        >自动同步仓储中，请等待...(若长时间未同步成功，请联系管理员！)</span>
        <button v-else-if="(infoList.isPush === '2' || (infoList.isPush === '0' && infoList.applyTypeId === '6')) && isEdit && metaEdit" class="pms-button-primary ml-5"
          @click="handleDoRetryApply(infoList,'02')"
        >
          同步仓储
        </button>
      </div>
      <div class="flex-box-right">
        <span
          class="color-red ml-5 mr-5"
          :class="{
            'color-green': +status === 1,
            'color-yellow': +status === 2,
          }"
        >状态:</span><span
          class="color-red"
          :class="{
            'color-green': +status === 1,
            'color-yellow': +status === 2,
          }"
        >{{ infoList.osName || "待出库" }}</span>
        <span class="ml-5">申领时间：</span><span class="mr-5">{{ infoList.createTime }}</span>
        <span class="ml-5">领用人:</span><span class="ml-5">{{ infoList.createBy }}</span>
        <el-button-group>
          <el-button
            v-if="status !== 1 && applyBtn &&isEdit && metaEdit"
            v-debounce="handleResetClickAll"
            class="pms-button-primary mr-5 ml-5"
            :disabled="repeatClickState"
          >批量撤销领用
          </el-button>
        </el-button-group>
      </div>
    </div>
    <wz-table
      :columns="wzApplicationColumn"
      :use-index="true"
      :table-data="applyDetails"
    >
      <!-- 设计数量 -->
      <!-- 累计申领数量 -->
      <template #header="{ col }">
        <div v-if="col.details">
          <el-tooltip
            class="item"
            effect="dark"
            :content="col.details"
            placement="top-start"
          >
            <span> {{ col.label }}</span>
          </el-tooltip>
        </div>
        <div v-else>
          {{ col.label }}
        </div>
      </template>
      <template #backAmount="{ row }">
        <div
          v-if="+row.backAmount > 0"
          class="click-row"
          @click="handleRemoveApplicationVisible(row)"
        >
          {{ row.backAmount }}
        </div>
        <div v-else>0</div>
      </template>
      <!-- 累计出库数量 -->
      <template #osAmount="{ row }">
        <div
          v-if="+row.osAmount > 0"
          class="click-row"
          @click="handleMaterialRemoveList(row)"
        >
          {{ row.osAmount }}
        </div>
        <div v-else>0</div>
      </template>
      <!-- 累计退库数量 -->
      <template #retreatAmount="{ row }">
        <div
          v-if="+row.retreatAmount > 0"
          class="click-row"
          @click="handleMaterialBackListVisible(row)"
        >
          {{ row.retreatAmount }}
        </div>
        <div v-else>0</div>
      </template>
      <!-- 未同步仓储撤销数量 -->
      <template #backingAmount="{ row }">
        <div
          v-if="+row.backingAmount > 0"
          class="click-row"
          @click="handleBackingAmountVisible(row)"
        >
          {{ row.backingAmount }}
        </div>
        <div v-else>0</div>
      </template>
      <template #ifSourceCode="{ row }">
        <div>
          {{ ifSourceCode(row.ifSourceCode) }}
        </div>
      </template>
      <!-- 本次申领数量 -->
      <template #labeledNum="{ row }">
        <div v-if="+row.amount">
          <el-input
            v-model="row.labeledNum"
            :disabled="nonarrivalDisabled(row)||!isEdit || !metaEdit"
            class="pms-wz-input el-table-inline"
          />
        </div>
      </template>
      <template #operation="{ row }">
        <span v-if="+row.applyType === 6 && +row.isPush !== 1" class="color-red">请先同步仓储</span>
        <span v-else-if="+row.applyType === 6" class="color-green">已完成</span>
        <span v-else-if="+row.noReceiveAmount <= 0" class="color-green">已完成</span>
        <span v-else-if="row.isPush == 0&&isEdit &&metaEdit" class="color-red">请先同步仓储</span>
        <el-button
          v-else-if="backReceiveBtn(row)"
          class="pms-button-primary mr-5"
          :disabled="repeatClickState"
          @click="handleResetClick(row)"
        >撤销领用
        </el-button>
      </template>
    </wz-table>
    <!-- 点击累计撤销数量后页面-撤销申请单-->
    <el-dialog
      v-dialogDrag
      :close-on-click-modal="false"
      :visible.sync="removeApplicationVisible"
      modal
      width="70%"
    >
      <div slot="title" class="dialog-header">撤销申请单</div>
      <div class="table-name-content">物资撤销申领</div>
      <wz-table
        :columns="removeApplication"
        :use-index="true"
        :table-data="fileData"
      />
    </el-dialog>
    <!-- 点击未同步仓储撤销申领列表 -->
    <el-dialog
      v-dialogDrag
      :close-on-click-modal="false"
      :visible.sync="doSaveBackInfoVisible"
      modal
      width="70%"
    >
      <div slot="title" class="dialog-header">撤销申请单</div>
      <div class="table-name-content">物资撤销申领</div>
      <wz-table
        :columns="doSaveBackInfoColumn"
        :use-index="true"
        :table-data="doSaveBackInfoData"
      >
        <template #operation="{ row }">
          <div>
            <el-button
              class="pms-button-primary"
              type="primary"
              @click="handleSynchronization(row)"
            >同步仓储
            </el-button>
          </div>
        </template>
      </wz-table>
    </el-dialog>
    <!-- 点击累计出库数量后页面 -->
    <el-dialog
      v-dialogDrag
      :close-on-click-modal="false"
      :visible.sync="materialRemoveListVisible"
      modal
      width="90%"
    >
      <div slot="title" class="dialog-header">出库单</div>
      <div class="table-name-content">物资出库</div>
      <wz-table
        :columns="materialRemoveList"
        :use-index="true"
        :table-data="materialRemoveData"
      >
        <!-- <template #outputType="{ row }">
                  <div>
                    {{ outputType(row) }}
                  </div>
                </template> -->
      </wz-table>
    </el-dialog>
    <!-- 点击累计退库数量后页面 -->
    <el-dialog
      v-dialogDrag
      :close-on-click-modal="false"
      :visible.sync="materialBackListVisible"
      modal
      width="90%"
    >
      <div slot="title" class="dialog-header">物资退库详情</div>
      <div class="color-red">
        1.若退库状态为退库申请中，请等待仓储完成退库。
      </div>
      <div class="color-red mb-10">
        2若退库状态为退库类型错误，请在项目操作-采购操作-物资申领/退库-退库类型修改模块进行调整。
      </div>
      <div class="table-name-content">物资退库申请单</div>
      <el-row>
        <el-col :span="14">
          <wz-table
            :columns="materialBackListLeft"
            :use-index="true"
            :table-data="materialBackListData"
          >
            <template #header="{ col }">
              <div class="header-wrapper">
                {{ col.label }}
              </div>
            </template>
            <template #ifSourceCode="{ row }">
              <div>{{ ifSourceCode(row.ifSourceCode) }}</div>
            </template>
          </wz-table>
          <div class="table-bottom-border" />
        </el-col>
        <el-col :span="10">
          <wz-table
            :columns="materialBackListRight"
            :table-data="materialBackListData"
          >
            <template #header="{ col }">
              <div class="header-wrapper">
                {{ col.label }}
              </div>
            </template>
            <template #ifSourceCode="{ row }">
              <div>{{ ifSourceCode(row.ifSourceCode) }}</div>
            </template>
            <template #reTryOperate="{ row }">
              <div v-if="reTryOperate(row) === 1">
                  <el-button
                      v-if="isEdit&&metaEdit"
                      class="pms-button-primary"
                      @click="reTryOperateBtn(row,'1')"
                  >
                      重试退库
                  </el-button>
              </div>
              <div v-else-if="reTryOperate(row) === 2">
                <el-button
                  v-if="isEdit&&metaEdit"
                  class="pms-button-primary"
                  @click="reTryOperateBtn(row,'2')"
                >
                  重试退库
                </el-button>
              </div>
              <div v-else />
            </template>
          </wz-table>
        </el-col>
      </el-row>
    </el-dialog>
  </div>
</template>
<script>
const MATERIAL_APPLICATION_LIST = [
    {
        label: '申领明细ID',
        prop: 'applySno',
        elProps: {
            'show-overflow-tooltip': true
        }
    },
    {
        label: '站址编码',
        prop: 'siteId',
        elProps: {
            'show-overflow-tooltip': true
        }
    },
    {
        label: '物料编码',
        prop: 'categoryCode',
        elProps: {
            'show-overflow-tooltip': true
        }
    },
    {
        label: '物料名称',
        prop: 'categoryName',
        elProps: {
            'show-overflow-tooltip': true
        }
    },
    {
        label: '自定义规格', prop: 'dwjl',
        elProps: {
            'show-overflow-tooltip': true
        }
    },
    {
        label: '主设备标识名称',
        prop: 'spuMainName',
        elProps: {
            width: '120px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '源头赋码标识', prop: 'ifSourceName', elProps: {
            width: '180px',
            'show-overflow-tooltip': true
        }
    },
    { label: '计量单位', prop: 'unit' },
    { label: '申领数量', prop: 'amount', details: '用户申领时填写的数量' },
    {
        label: '累计撤销数量',
        prop: 'backAmount',
        details: '当前申领单累计撤销退库的数量'
    },
    {
        label: '未同步仓储撤销数量',
        prop: 'backingAmount',
        elProps: {
            width: '150px',
            'show-overflow-tooltip': true
        },
        details: '撤销退库未同步仓储成功的数量'
    },
    {
        label: '累计出库数量',
        prop: 'osAmount',
        details: '当前申领单累计出库总数'
    },
    {
        label: '累计退库数量',
        prop: 'retreatAmount',
        details: '当前申领单累计退库完成总数'
    },
    {
        label: '待出库数量',
        prop: 'noReceiveAmount',
        details: '该申领单申领数量-已出库完成数量'
    },
    {
        label: '本次撤销领用数量',
        prop: 'labeledNum',
        elProps: {
            width: '120px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '操作',
        prop: 'operation',
        elProps: {
            width: '120px',
            'show-overflow-tooltip': true
        }
    }
]
const REMOVE_APPLICATION = [
    {
        label: '撤销申领单',
        prop: 'recipientApplyId',
        elProps: {
            width: '120px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '站址编码',
        prop: 'siteId',
        elProps: {
            width: '120px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '物料编码',
        prop: 'categoryCode',
        elProps: {
            width: '120px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '物料名称',
        prop: 'categoryName',
        elProps: {
            'show-overflow-tooltip': true
        }
    },
    {
        label: '自定义规格', prop: 'dwjl', elProps: {
            'show-overflow-tooltip': true
        }
    },
    {
        label: '计量单位', prop: 'unit', elProps: {
            'show-overflow-tooltip': true
        }
    },
    {
        label: '撤销申领数量', prop: 'backAmount', elProps: {
            'show-overflow-tooltip': true
        }
    },
    {
        label: '撤销人', prop: 'createBy', elProps: {
            'show-overflow-tooltip': true
        }
    },
    {
        label: '撤销申领时间',
        prop: 'createTime',
        details: '设计清单中该物料的数量'
    }
]
const MATERIAL_REMOVE_LIST = [
    {
        label: '出库订单号',
        prop: 'orderId',
        elProps: {
            width: '120px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '出库明细行号',
        prop: 'osDetailId',
        elProps: {
            width: '120px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '物料编码',
        prop: 'categoryCode',
        elProps: {
            width: '120px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '物料名称',
        prop: 'categoryName',
        elProps: {
            width: '120px',
            'show-overflow-tooltip': true
        }
    },
    { label: '规格型号', prop: 'formPattern' },
    {
        label: '源头赋码标识',
        prop: 'ifSourceName',
        elProps: {
            width: '180px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '商品编码',
        prop: 'materialCode',
        elProps: {
            width: '120px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '商品名称',
        prop: 'materialName',
        elProps: {
            width: '120px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '出库数量', prop: 'osAmount', elProps: {
            width: '120px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '是否利旧资产',
        prop: 'outputType',
        elProps: {
            width: '120px'
        }
    },
    {
        label: '资产编码', prop: 'assetCode', elProps: {
            width: '120px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '资产名称', prop: 'assetName', elProps: {
            width: '120px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '合同编码', prop: 'contractCode', elProps: {
            width: '120px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '自定义规格',
        prop: 'dwjl',
        elProps: {
            width: '120px',
            'show-overflow-tooltip': true
        }
    },
    { label: '计量单位', prop: 'unit' },
    {
        label: '不含税单价',
        prop: 'price',
        elProps: {
            width: '120px'
        }
    },
    {
        label: '含税总金额',
        prop: 'totalTaxAmount',
        elProps: {
            width: '120px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '领用人',
        prop: 'createBy',
        elProps: {
            width: '120px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '出库时间',
        prop: 'osTime',
        elProps: {
            width: '120px',
            'show-overflow-tooltip': true
        }
    }
]
const MATERIAL_BACK_LIST_LEFT = [
    {
        label: '站址编码',
        prop: 'siteId',
        elProps: {
            'show-overflow-tooltip': true
        }
    },
    {
        label: '物料编码',
        prop: 'categoryCode',
        elProps: {
            width: '80px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '物料名称',
        prop: 'categoryName',
        elProps: {
            'show-overflow-tooltip': true
        }
    },
    {
        label: '主设备标识名称',
        prop: 'spuMainName',
        elProps: {
            width: '110px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '源头赋码标识',
        prop: 'ifSourceName',
        elProps: {
            width: '180px',
            'show-overflow-tooltip': true
        }
    },
    { label: '退库数量', prop: 'retreatAmount' }
]
const MATERIAL_BACK_LIST_RIGHT = [
    {
        label: '退库状态', prop: 'retreatStateName', elProps: {
            'show-overflow-tooltip': true
        }
    },
    {
        label: '操作',
        prop: 'operation',
        elProps: {
            width: '100px'
        }
    },
    {
        label: '推送仓储状态',
        prop: 'pushName',
        elProps: {
            width: '120px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '退库申请单号',
        prop: 'retreatDetailId',
        elProps: {
            width: '120px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '退库类型',
        prop: 'refundType',
        elProps: {
            width: '120px',
            'show-overflow-tooltip': true
        }
    },
    { label: '退库类别', prop: 'pmsRetreatType' },
    { label: '规格型号', prop: 'formPattern' },
    {
        label: '商品编码',
        prop: 'materialCode',
        elProps: {
            width: '120px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '商品名称',
        prop: 'materialName',
        elProps: {
            width: '120px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '退库发起人',
        prop: 'createBy',
        elProps: {
            width: '120px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '退库申请时间',
        prop: 'createTime',
        elProps: {
            width: '120px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '退库完成时间',
        prop: 'retreatTime',
        elProps: {
            width: '120px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '仓储返回信息',
        prop: 'backMsg',
        elProps: {
            width: '120px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '自定义规格',
        prop: 'dwjl',
        elProps: {
            width: '120px',
            'show-overflow-tooltip': true
        }
    },
    { label: '计量单位', prop: 'unit' },
    {
        label: '不含税单价',
        prop: 'price',
        elProps: {
            width: '120px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '含税总金额',
        prop: 'totalTaxAmount',
        elProps: {
            width: '120px',
            'show-overflow-tooltip': true
        }
    }
]
const DO_SAVE_BACK_INFO_COLUMN = [
    {
        label: '撤销申领单',
        prop: 'recipientApplyId',
        elProps: {
            width: '120px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '站址编码',
        prop: 'siteId',
        elProps: {
            width: '120px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '物料编码',
        prop: 'categoryCode',
        elProps: {
            width: '120px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '物料名称',
        prop: 'categoryName',
        elProps: {
            'show-overflow-tooltip': true
        }
    },
    {
        label: '自定义规格', prop: 'dwjl', elProps: {
            'show-overflow-tooltip': true
        }
    },
    {
        label: '计量单位', prop: 'unit', elProps: {
            'show-overflow-tooltip': true
        }
    },
    {
        label: '撤销申领数量', prop: 'backAmount', elProps: {
            'show-overflow-tooltip': true
        }
    },
    {
        label: '撤销人', prop: 'createBy', elProps: {
            'show-overflow-tooltip': true
        }
    },
    {
        label: '撤销申领时间',
        prop: 'createTime',
        details: '设计清单中该物料的数量',
        elProps: {
            width: '140px',
            'show-overflow-tooltip': true
        }
    },
    {
        label: '操作',
        prop: 'operation',
        elProps: {
            width: '120px'
        }
    }
]
// 系统常量配置
import wzTable from './cTable'
import {
    queryOsEquipList,
    queryRetreatEquipList,
    doSaveBackInfo,
    queryBackEquipList,
    getSpuUnitAccByMaterialCode,
    queryBackingEquipList,
    doRetryBackInfo,
    doRetryApply,
    queryBackWhole,
    updateRetreatInfoById, sendMaterialTransferInfo
} from '@/api/material'

export default {
    name: 'MaterialsInfoList',
    components: { wzTable },
    props: {
        infoList: {
            type: Object,
            default: () => ({})
        },
        note: {
            type: String,
            default: ''
        },
        projectInfo: {
            type: Object,
            default: () => ({
            })
        },
        metaEdit: {
            type: Boolean,
            default: true
        }
    },
    data() {
        return {
            fileList: [],
            fileData: [],
            materialRemovalVisible: false,
            materialBackVisible: false,
            arrivalVisible: false,
            planGetTime: '',
            wzApplicationColumn: [],
            nonarrivalNumForm: {
                nonarrivalNum: ''
            },
            materialsRemarks: '',
            applyDetails: [],
            removeApplicationVisible: false,
            materialRemoveListVisible: false,
            materialBackListVisible: false,
            removeApplication: [],
            materialRemoveList: [],
            materialRemoveData: [],
            materialBackListLeft: [],
            materialBackListRight: [],
            materialBackListData: [],
            doSaveBackInfoColumn: [],
            repeatClickState: false,
            doSaveBackInfoVisible: false,
            doSaveBackInfoData: [],
            currentRow: '',
            unAbleRow: {},
            applyBtn:false
        }
    },
    computed: {
        status() {
            if (
                +this.unAbleRow?.applyType === 6 &&
                +this.unAbleRow?.isPush !== 1
            ) {
                return 1
            }
            if (+this.unAbleRow?.isPush === 0) {
                return 1
            }
            if (this.infoList.osName === '部分出库') {
                return 2
            }
            this.getApplyBtn();
            return this.infoList.osName === '已完成' ? 1 : 0
        },
        query() {
            return this.$route.query
        },
        isEdit() {
            if (this.projectInfo) {
                return !!+this.projectInfo.isEdit
            }
            return true
        },
        reTryOperate() {
            return (row) => {
                if (
                    +row.isPush !== 1 &&
                    +row.pmsRetreat === 37 &&
                    row.retreatState === 0
                ) {
                    return 1
                }
                if (
                    +row.isPush === 2 &&
                    +row.pmsRetreat !== 37 &&
                    row.retreatState === 0
                ) {
                    return 2
                }
                return 3
            }
        },
        backReceiveBtn() {
            return (row) => {
                return !(+row.applyType === 6 && +row.isPush !== 1) && !(+row.applyType === 6) && this.optimizeNewOne(row)
            }
        }
    },
    watch: {
        infoList: {
            handler(newValue) {
                this.applyDetails = newValue.applyDetails.map((item) => {
                    return {
                        ...item,
                        labeledNum: ''
                    }
                })
            },
            deep: true,
            immediate: true
        }
    },
    created() {
        this.wzApplicationColumn = JSON.parse(
            JSON.stringify(MATERIAL_APPLICATION_LIST)
        )
        if (
            !(this.query.manageMode === '03' || this.query.manageMode === '04')
        ) {
            this.wzApplicationColumn.splice(1, 1)
        }
        this.removeApplication = JSON.parse(JSON.stringify(REMOVE_APPLICATION))
        this.doSaveBackInfoColumn = JSON.parse(
            JSON.stringify(DO_SAVE_BACK_INFO_COLUMN)
        )
        this.materialRemoveList = JSON.parse(
            JSON.stringify(MATERIAL_REMOVE_LIST)
        )
        this.materialBackListLeft = JSON.parse(
            JSON.stringify(MATERIAL_BACK_LIST_LEFT)
        )
        this.materialBackListRight = JSON.parse(
            JSON.stringify(MATERIAL_BACK_LIST_RIGHT)
        )
    },
    methods: {
        getApplyBtn(){
            if(+this.infoList.applyTypeId === 6){
                this.applyBtn=false
            }else{
                this.applyBtn=true
            }
        },
        // 2024-11-4阻断问题if过多解决方案
        optimizeNewOne(row) {
            return !(+row.noReceiveAmount <= 0) && !(row.isPush === 0) && this.isEdit && this.metaEdit
        },
        // outputType(row) {

        //     if (+row.outputType === 25) {
        //         return '是'
        //     }
        // },
        ifSourceCode(ifSourceCode) {
            if (+ifSourceCode) {
                return '否'
            }
            if (ifSourceCode === 0 || ifSourceCode === '0') {
                return '是'
            }
            return ''
        },
        nonarrivalDisabled(row) {
            this.unAbleRow = {}
            if (+row.applyType === 6 && +row.isPush !== 1) {
                this.unAbleRow = row
                return true
            }
            if (+row.isPush === 0) {
                this.unAbleRow = row
                return true
            }
            // 待出库数量为0 时代表以完成
            if (!+row.noReceiveAmount) {
                return true
            }
            if (+row.noReceiveAmount && +row.applyType === 6) {
                return true
            }
            if (+row.noReceiveAmount) {
                return false
            }
            if (+row.amount && (this.status === 1 || this.status === 2)) {
                return true
            }
            return false
        },
        // 切换每页显示条数时
        handleSizeChange(val) {
            this.pageSize = val
            console.log('每页' + val + '条')
            // 代码逻辑
        },
        // 点击页码时
        handleCurrentChange(val) {
            this.currentPageValue = val
            console.log('当前页' + val)
            // 代码逻辑
        },
        // 点击累计撤销数量
        async handleRemoveApplicationVisible(row) {
            this.currentRow = row
            const res = await queryBackEquipList({ applySno: row.applySno })
            if (+res.code === 200) {
                this.fileData = res.data
                this.removeApplicationVisible = true
            }
        },
        // 点击累计出库数量后
        async handleMaterialRemoveList(row) {
            this.currentRow = row
            const params = {
                applyId: row.applySno,
                categoryCode: row.categoryCode,
                dwjl: row.dwjl,
                subPrjId: row.subPrjId
            }
            const res = await queryOsEquipList(params)
            if (+res.code === 200) {
                this.materialRemoveData = res.data
                this.materialRemoveListVisible = true
            }
        },
        // 点击累计仓库数量
        async handleMaterialBackListVisible(row) {
            this.currentRow = row
            const params = {
                applyId: row.applySno,
                categoryCode: row.categoryCode,
                dwjl: row.dwjl,
                subPrjId: row.subPrjId
            }
            if (
                this.query.manageMode === '03' ||
                this.query.manageMode === '04'
            ) {
                const queryRetreatEquipListWholeRes = await queryBackWhole(
                    params
                )
                if (+queryRetreatEquipListWholeRes.code === 200) {
                    this.materialBackListData =
                        queryRetreatEquipListWholeRes.data
                    this.materialBackListVisible = true
                }
                return
            }
            const res = await queryRetreatEquipList(params)
            if (+res.code === 200) {
                this.materialBackListData = res.data
                this.materialBackListVisible = true
            }
        },
        async handleBackingAmountVisible(row) {
            this.currentRow = row
            const res = await queryBackingEquipList({ applySno: row.applySno })
            if (+res.code === 200) {
                this.doSaveBackInfoData = res.data
                this.doSaveBackInfoVisible = true
            }
        },
        //   撤销领用
        async handleResetClick(row, type) {
            this.currentRow = row
            const params = {
                amount: row.amount,
                applySno: row.applySno,
                applyType: row.applyType,
                backAmount: row.backAmount,
                backingAmount: row.backingAmount,
                categoryCode: row.categoryCode,
                categoryName: row.categoryName,
                dwjl: row.dwjl,
                ifSourceCode: row.ifSourceCode,
                isPush: row.isPush,
                isStandardProduct: row.isStandardProduct,
                isStandardProductName: row.isStandardProductName,
                noReceiveAmount: row.noReceiveAmount,
                osAmount: row.osAmount,
                price: row.price,
                receiveAmount: row.labeledNum,
                recipientApplyId: row.recipientApplyId,
                retreatAmount: row.retreatAmount,
                siteId: row.siteId,
                spuMainName: row.spuMainName,
                subPrjId: row.subPrjId,
                unit: row.unit,
                _id: row._id,
                _state: row._state,
                _uid: row._uid
            }
            const materialCheckParams = {
                receiveAmount: row.labeledNum,
                materialCode: row.categoryCode,
                amountType: 0, // 撤销领用
                siteName: this.projectInfo.siteName || '',
                queryType:
                    this.query.manageMode !== '03' &&
                    this.query.manageMode !== '04'
                        ? 1
                        : '',
                note: this.note,
                siteId: row.siteId
            }
            this.repeatClickState = true
            const timer = setTimeout(() => {
                this.repeatClickState = false
                clearTimeout(timer)
            }, 5 * 1000)
            const resMaterialCode = await getSpuUnitAccByMaterialCode(
                materialCheckParams
            )

            //  const resMaterialCode = { code: 200 }
            if (+resMaterialCode.code === 200) {
                let loading = ''
                if (!type) {
                    loading = this.$loading({
                        lock: true,
                        text: '物资撤销申领中,请稍后...',
                        spinner: 'el-icon-loading',
                        fullscreen: true
                    })
                }
                try {
                    const res = await doSaveBackInfo(params)
                    if (+res.code === 200) {
                        // if (!type) {
                            this.$message.success('撤销成功')
                        // }
                    }
                } finally {
                    this.$emit('doSaveBackInfo')
                    if (!type) {
                        loading.close()
                    }
                }
            }
        },
        // 批量撤销领用
        async handleResetClickAll() {
            let count = 0
            const loading = this.$loading({
                lock: true,
                text: '物资撤销申领中,请稍后...',
                spinner: 'el-icon-loading',
                fullscreen: true
            })
            try {
                for (const item of this.applyDetails) {
                    let params = ''
                    if (+item.labeledNum <= 0 || +item.noReceiveAmount <= 0) {
                        this.repeatClickState = true
                        const timer = setTimeout(() => {
                            this.repeatClickState = false
                            clearTimeout(timer)
                        }, 5 * 1000)
                        count++
                    } else {
                        params = { ...item }
                        await this.handleResetClick(
                            {
                                ...params
                            },
                            'all'
                        )
                    }
                    if (count === this.applyDetails.length) {
                        return this.$message.warning(
                            '请正确输入物资撤销领用数量，撤销领用数量不能大于未出库数量！撤销领用数量精度需正确'
                        )
                    }
                }
            } catch (error) {
                console.log(error)
            } finally {
                this.$emit('doSaveBackInfo')
                loading.close()
            }
        },
        // 同步撤销仓储
        async handleSynchronization(row) {
            const loading = this.$loading({
                lock: true,
                text: '正在执行撤销申领同步仓储，请稍后...',
                spinner: 'el-icon-loading',
                fullscreen: false
            })
            try {
                const res = await doRetryBackInfo({
                    applyId: row.recipientApplyId,
                    parentAppId: row.parentApplyId
                })
                if (+res.code === 200) {
                    this.$message.success(res.data || '撤销成功！')
                    this.doSaveBackInfoVisible = false
                }
            } catch (error) {
                console.log(error)
            } finally {
                this.$emit('doSaveBackInfo')

                loading.close()
            }
        },
        async reTryOperateBtn(row,type) {
            const loading = this.$loading({
                lock: true,
                text: '正在重推仓储申领单，请稍后...',
                spinner: 'el-icon-loading',
                fullscreen: false
            })
            try {
                let res={}
                if(type === '1'){
                    //调新接口
                    res = await sendMaterialTransferInfo({
                        retreatDetailId: row.retreatDetailId,
                        recipientApplyId:"",
                    })
                }else{
                    res = await updateRetreatInfoById({
                        retreatDetailId: row.retreatDetailId
                    })
                }
                if (+res.code === 200) {
                    this.$message.success('提交成功!')
                }
            } catch (error) {
                console.log(error)
            } finally {
                loading.close()
            }
        },
        async handleDoRetryApply(infoList,type) {
            console.log(infoList)
            const loading = this.$loading({
                lock: true,
                text: '正在重推仓储申领单，请稍后...',
                spinner: 'el-icon-loading',
                fullscreen: false
            })
            try {
                let res = {}
                if(type === '01'){
                    res = await doRetryApply({
                        applyId: infoList.recipientApplyId
                    })
                }else{
                    //调新接口
                    res = await sendMaterialTransferInfo({
                        retreatDetailId:'',
                        recipientApplyId:infoList.recipientApplyId,
                    })
                }
                if (+res.code === 200) {
                    this.$message.success(res.data || '提交成功!')
                }
            } catch (error) {
                console.log(error)
            } finally {
                this.$emit('doSaveBackInfo')
                loading.close()
            }
        }
    }
}
</script>
<style scoped lang="scss">
.el-upload--text {
    width: 100%;
}

.btnflex {
    display: flex;
    justify-content: space-between;
}

::v-deep .color-yellow {
    color: #ffc481 !important;
}

.color-red {
    color: #eb4b4b;
}

.color-green {
    color: #77dfaf;
}

.color-gray {
    color: #ccc;
}

.el-table th {
    padding: 0px 0;
    text-align: center;
    font-size: 12px;
    color: #333333;
    letter-spacing: 0;
}

.el-table td {
    padding: 0px 0;
    text-align: center;
    font-size: 2px;
    color: #333333;
    letter-spacing: 0;
}

.click-row {
    color: #53c7f8;
    cursor: pointer;
}

.materials-remark-wrapper {
    position: relative;
    border: 1px solid #ccc;
    padding-left: 10px;
    padding-right: 10px;
    padding-top: 20px;
    padding-bottom: 10px;

    &-title {
        position: absolute;
        left: 50%;
        top: -13px;
        background: #fff;
        font-weight: bold;
    }
}

.mt-10 {
    margin-top: 10px;
}

.mb-10 {
    margin-bottom: 10px;
}

.mr-5 {
    margin-right: 5px !important;
}

.ml-5 {
    margin-left: 5px !important;
}

.flex-box {
    display: flex;
    width: 100%;
    align-items: center;

    &-left {
        margin-right: auto;
    }
}

.flex-right {
    width: 100%;
    flex-direction: row-reverse;
}

.pms-el-datepicker {
    margin-left: 10px;
    margin-right: 10px;
    height: 24px;

    ::v-deep .el-input__inner {
        height: 24px;
    }

    ::v-deep .el-input__icon {
        line-height: 20px;
    }
}

.header-wrapper {
    width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pms-wz-input {
    ::v-deep .el-input__inner {
        background-color: #fffaee !important;
    }

    ::v-deep .el-input__inner:disabled {
        background-color: #f5f7fa !important;
    }
}
</style>
